package com.zxx.pattern.mediatorPattern.mediator1;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zxx on 2021/5/11
 */
public class ChatRoom {
    private List<User> users;

    public ChatRoom() {
        System.out.println("聊天室开启！！");
        users = new ArrayList<User>();
    }

    public void addUser(User user) {
        System.out.println(user.getName() + "加入了聊天室！");
        users.add(user);
    }

    public void operateMessage(Message message) {
        User fromUser = message.getFromUser();
        for (User user : users) {
            if (fromUser != user) {
                System.out.println(user.getName() + "收到了来自" + fromUser.getName() + "的信息：" +
                        message.getContent());
            }
        }

    }
}
